<?php

/**
 * PHP策略模式
 * Class Printer
 */
class Printer
{

    private $obj;

    public function __construct($obj)
    {
        $this->obj = $obj;
    }

    public function printer($str)
    {
        echo $this->obj->format($str).PHP_EOL;
    }
}

class LowerCaseStrategy
{
    function format($str)
    {
        return strtolower($str);
    }
}

class UpperCaseStrategy
{
    function format($str)
    {
        return strtoupper($str);
    }
}

$str = 'Hello World';
$obj1 = new LowerCaseStrategy();
$obj2 = new UpperCaseStrategy();
$printer1 = new Printer($obj1);
$printer2 = new Printer($obj2);
$printer1->printer($str);
$printer2->printer($str);

